﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LotteryVote.Logic.Web;
using LotteryVote.Logic;

namespace LotteryVote
{
    public partial class BetOrderList : AuthorizePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                BindBetList();
        }
        BetFacade betFacade = new BetFacade();
        void BindBetList()
        {

            gv_betList.DataSource = betFacade.GetBetSheets(CurrentUser.UserId);
            gv_betList.DataBind();
        }

        protected void gv_betList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int sheetId = Convert.ToInt32(e.CommandArgument);
            if (e.CommandName == "GetOrder")
            {
                gv_betOrder.DataSource = betFacade.GetBetOrderBySheet(sheetId);
                gv_betOrder.DataBind();
            }
            if (e.CommandName == "del")
            {
                betFacade.CancelBetSheet(sheetId, CurrentUser.UserId);
            }
        }

        protected void gv_betOrder_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int orderId = Convert.ToInt32(e.CommandArgument);
            betFacade.CancelBetOrder(orderId, CurrentUser.UserId);
        }
    }
}